package com.imooc.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @ClassName Swagger2
 * @Description TODO
 * @Author xuhang1
 * @Data 2020/4/30 8:41
 * @Version 1.0
 **/
@Configuration
@EnableSwagger2
public class Swagger2 {

    // http://localhots:8088/swagger-ui.html
    // http://localhots:8088/doc.html

    // 配置swagger2核心配置
    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2) // 制定swagger版本
                .apiInfo(apiInfo())                    // 定义文档api的信息
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.imooc.controller")) // 指定controller
                .paths(PathSelectors.any())           // 选择所有controller
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("天天吃货 API接口")
                .contact(new Contact("imooc","www.imooc.com","abc@imooc.com"))
                .description("天天吃货接口文档")
                .version("1.0")
                .termsOfServiceUrl("www.imooc.com")
                .build();
    }
}
